Skip to contentSkip to conversation

Change in openvpn[master]: dco: only pass struct context to init function

Openvpn-devel In review ordex (Code Review) 2 participants 11 messages Jul 22, 2025 – Jul 23, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1753215725000.I673a17f8c5dec66cc6c28c1ed44780a7a63927d7@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email

to review the following change.

Change subject: dco: only pass struct context to init function
......................................................................

dco: only pass struct context to init function

Future DCO code will require accessing the multi member of the context object.

For this reason a pointer to the context has to be stored in the DCO context along with the rest.

At this point, rather than making the call to ovpn_dco_init() longer with more and more parameters, pass the struct context only and let the implementation extract the needed fields.

Change-Id I673a17f8c5dec66cc6c28c1ed44780a7a63927d7

---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/init.c

4 files changed, 13 insertions(+), 9 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/94/1094/1

src/openvpn/dco.h +2 -4
index f38316d..9c5c01a 100644
@@ -104,12 +104,10 @@
 /**
  * Initialize the DCO context
  *
- * @param mode      the instance operating mode (P2P or multi-peer)
- * @param dco       the context to initialize
- * @param dev_node  device node, used on Windows to specify certain DCO adapter
+ * @param c         the main instance context
  * @return          true on success, false otherwise
  */
-bool ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node);
+bool ovpn_dco_init(struct context *c);
 
 /**
  * Open/create a DCO interface
src/openvpn/dco_freebsd.c +2 -2
index b8816c6..98d8fb5 100644
@@ -165,9 +165,9 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    if (open_fd(dco) < 0)
+    if (open_fd(&c->c1.tuntap->dco) < 0)
     {
         msg(M_ERR, "Failed to open socket");
         return false;
src/openvpn/dco_linux.c +8 -2
index f04ebfe..c92c196 100644
@@ -438,9 +438,11 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case CM_TOP:
             dco->ifmode = OVPN_MODE_MP;
@@ -454,6 +456,10 @@
             ASSERT(false);
     }
 
+    /* store pointer to context as it may be required by message
+     * parsing routines
+     */
+    dco->c = c;
     ovpn_dco_init_netlink(dco);
     return true;
 }
src/openvpn/init.c +1 -1
index 77747a2..aac8a6a 100644
@@ -2007,7 +2007,7 @@
 
         if (dco_enabled(&c->options))
         {
-            ovpn_dco_init(c->mode, &c->c1.tuntap->dco, c->options.dev_node);
+            ovpn_dco_init(c);
         }
 
         /* open the tun device */

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I673a17f8c5dec66cc6c28c1ed44780a7a63927d7
Gerrit-Change-Number: 1094
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email

to look at the new patch set (#2).

Change subject: dco: only pass struct context to init function
......................................................................

dco: only pass struct context to init function

Future DCO code will require accessing the multi member of the context object.

For this reason a pointer to the context has to be stored in the DCO context along with the rest.

At this point, rather than making the call to ovpn_dco_init() longer with more and more parameters, pass the struct context only and let the implementation extract the needed fields.

Change-Id I673a17f8c5dec66cc6c28c1ed44780a7a63927d7

---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/init.c

5 files changed, 15 insertions(+), 9 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/94/1094/2

src/openvpn/dco.h +2 -4
index f38316d..9c5c01a 100644
@@ -104,12 +104,10 @@
 /**
  * Initialize the DCO context
  *
- * @param mode      the instance operating mode (P2P or multi-peer)
- * @param dco       the context to initialize
- * @param dev_node  device node, used on Windows to specify certain DCO adapter
+ * @param c         the main instance context
  * @return          true on success, false otherwise
  */
-bool ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node);
+bool ovpn_dco_init(struct context *c);
 
 /**
  * Open/create a DCO interface
src/openvpn/dco_freebsd.c +2 -2
index b8816c6..98d8fb5 100644
@@ -165,9 +165,9 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    if (open_fd(dco) < 0)
+    if (open_fd(&c->c1.tuntap->dco) < 0)
     {
         msg(M_ERR, "Failed to open socket");
         return false;
src/openvpn/dco_linux.c +8 -2
index f04ebfe..c92c196 100644
@@ -438,9 +438,11 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case CM_TOP:
             dco->ifmode = OVPN_MODE_MP;
@@ -454,6 +456,10 @@
             ASSERT(false);
     }
 
+    /* store pointer to context as it may be required by message
+     * parsing routines
+     */
+    dco->c = c;
     ovpn_dco_init_netlink(dco);
     return true;
 }
src/openvpn/dco_linux.h +2 -0
index 676b8cd..5e61cf1 100644
@@ -65,6 +65,8 @@
     struct nl_cb *nl_cb;
     int status;
 
+    struct context *c;
+
     enum ovpn_mode ifmode;
 
     int ovpn_dco_id;
src/openvpn/init.c +1 -1
index 77747a2..aac8a6a 100644
@@ -2007,7 +2007,7 @@
 
         if (dco_enabled(&c->options))
         {
-            ovpn_dco_init(c->mode, &c->c1.tuntap->dco, c->options.dev_node);
+            ovpn_dco_init(c);
         }
 
         /* open the tun device */

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I673a17f8c5dec66cc6c28c1ed44780a7a63927d7
Gerrit-Change-Number: 1094
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, ordex, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email )

Change subject: dco: only pass struct context to init function
......................................................................

Patch Set 2: Code-Review-2

(1 comment)

Patchset:

PS2:
dco.h has

```
static inline bool
ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
{
    return true;
}
```

which also needs to be adjusted...

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I673a17f8c5dec66cc6c28c1ed44780a7a63927d7
Gerrit-Change-Number: 1094
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 23 Jul 2025 06:19:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.

stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email )

Change subject: dco: only pass struct context to init function
......................................................................

Patch Set 2:

(1 comment)

Patchset:

PS2:

Quoted 1 line

dco.h has […]

Same goes to dco_win.c

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I673a17f8c5dec66cc6c28c1ed44780a7a63927d7
Gerrit-Change-Number: 1094
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 23 Jul 2025 08:16:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email

to look at the new patch set (#3).

Change subject: dco: only pass struct context to init function
......................................................................

dco: only pass struct context to init function

Future DCO code will require accessing the multi member of the context object.

For this reason a pointer to the context has to be stored in the DCO context along with the rest.

At this point, rather than making the call to ovpn_dco_init() longer with more and more parameters, pass the struct context only and let the implementation extract the needed fields.

Change-Id I673a17f8c5dec66cc6c28c1ed44780a7a63927d7

---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/dco_win.c
M src/openvpn/init.c

6 files changed, 20 insertions(+), 12 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/94/1094/3

src/openvpn/dco.h +3 -5
index f38316d..9078417 100644
@@ -104,12 +104,10 @@
 /**
  * Initialize the DCO context
  *
- * @param mode      the instance operating mode (P2P or multi-peer)
- * @param dco       the context to initialize
- * @param dev_node  device node, used on Windows to specify certain DCO adapter
+ * @param c         the main instance context
  * @return          true on success, false otherwise
  */
-bool ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node);
+bool ovpn_dco_init(struct context *c);
 
 /**
  * Open/create a DCO interface
@@ -297,7 +295,7 @@
 }
 
 static inline bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
     return true;
 }
src/openvpn/dco_freebsd.c +2 -2
index b8816c6..98d8fb5 100644
@@ -165,9 +165,9 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    if (open_fd(dco) < 0)
+    if (open_fd(&c->c1.tuntap->dco) < 0)
     {
         msg(M_ERR, "Failed to open socket");
         return false;
src/openvpn/dco_linux.c +8 -2
index 3652a49..ec6efaa 100644
@@ -438,9 +438,11 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case CM_TOP:
             dco->ifmode = OVPN_MODE_MP;
@@ -454,6 +456,10 @@
             ASSERT(false);
     }
 
+    /* store pointer to context as it may be required by message
+     * parsing routines
+     */
+    dco->c = c;
     ovpn_dco_init_netlink(dco);
     return true;
 }
src/openvpn/dco_linux.h +2 -0
index 676b8cd..5e61cf1 100644
@@ -65,6 +65,8 @@
     struct nl_cb *nl_cb;
     int status;
 
+    struct context *c;
+
     enum ovpn_mode ifmode;
 
     int ovpn_dco_id;
src/openvpn/dco_win.c +4 -2
index 83db739..1d20247 100644
@@ -188,8 +188,10 @@
  * state. The server socket should be initialized later by dco_mp_start_vpn().
  */
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
     switch (mode)
     {
         case MODE_POINT_TO_POINT:
@@ -198,7 +200,7 @@
             break;
 
         case MODE_SERVER:
-            ovpn_dco_init_mp(dco, dev_node);
+            ovpn_dco_init_mp(dco, c->options.dev_node);
             break;
 
         default:
src/openvpn/init.c +1 -1
index 77747a2..aac8a6a 100644
@@ -2007,7 +2007,7 @@
 
         if (dco_enabled(&c->options))
         {
-            ovpn_dco_init(c->mode, &c->c1.tuntap->dco, c->options.dev_node);
+            ovpn_dco_init(c);
         }
 
         /* open the tun device */

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I673a17f8c5dec66cc6c28c1ed44780a7a63927d7
Gerrit-Change-Number: 1094
Gerrit-PatchSet: 3
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email

to look at the new patch set (#4).

Change subject: dco: only pass struct context to init function
......................................................................

dco: only pass struct context to init function

Future DCO code will require accessing the multi member of the context object.

For this reason a pointer to the context has to be stored in the DCO context along with the rest.

At this point, rather than making the call to ovpn_dco_init() longer with more and more parameters, pass the struct context only and let the implementation extract the needed fields.

Change-Id I673a17f8c5dec66cc6c28c1ed44780a7a63927d7

---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/dco_win.c
M src/openvpn/init.c

6 files changed, 21 insertions(+), 13 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/94/1094/4

src/openvpn/dco.h +3 -5
index f38316d..9078417 100644
@@ -104,12 +104,10 @@
 /**
  * Initialize the DCO context
  *
- * @param mode      the instance operating mode (P2P or multi-peer)
- * @param dco       the context to initialize
- * @param dev_node  device node, used on Windows to specify certain DCO adapter
+ * @param c         the main instance context
  * @return          true on success, false otherwise
  */
-bool ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node);
+bool ovpn_dco_init(struct context *c);
 
 /**
  * Open/create a DCO interface
@@ -297,7 +295,7 @@
 }
 
 static inline bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
     return true;
 }
src/openvpn/dco_freebsd.c +2 -2
index b8816c6..98d8fb5 100644
@@ -165,9 +165,9 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    if (open_fd(dco) < 0)
+    if (open_fd(&c->c1.tuntap->dco) < 0)
     {
         msg(M_ERR, "Failed to open socket");
         return false;
src/openvpn/dco_linux.c +8 -2
index 3652a49..ec6efaa 100644
@@ -438,9 +438,11 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case CM_TOP:
             dco->ifmode = OVPN_MODE_MP;
@@ -454,6 +456,10 @@
             ASSERT(false);
     }
 
+    /* store pointer to context as it may be required by message
+     * parsing routines
+     */
+    dco->c = c;
     ovpn_dco_init_netlink(dco);
     return true;
 }
src/openvpn/dco_linux.h +2 -0
index 676b8cd..5e61cf1 100644
@@ -65,6 +65,8 @@
     struct nl_cb *nl_cb;
     int status;
 
+    struct context *c;
+
     enum ovpn_mode ifmode;
 
     int ovpn_dco_id;
src/openvpn/dco_win.c +5 -3
index 83db739..e5a33a0 100644
@@ -188,9 +188,11 @@
  * state. The server socket should be initialized later by dco_mp_start_vpn().
  */
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case MODE_POINT_TO_POINT:
             dco->ifmode = DCO_MODE_P2P;
@@ -198,7 +200,7 @@
             break;
 
         case MODE_SERVER:
-            ovpn_dco_init_mp(dco, dev_node);
+            ovpn_dco_init_mp(dco, c->options.dev_node);
             break;
 
         default:
src/openvpn/init.c +1 -1
index 77747a2..aac8a6a 100644
@@ -2007,7 +2007,7 @@
 
         if (dco_enabled(&c->options))
         {
-            ovpn_dco_init(c->mode, &c->c1.tuntap->dco, c->options.dev_node);
+            ovpn_dco_init(c);
         }
 
         /* open the tun device */

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I673a17f8c5dec66cc6c28c1ed44780a7a63927d7
Gerrit-Change-Number: 1094
Gerrit-PatchSet: 4
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, ordex, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email )

Change subject: dco: only pass struct context to init function
......................................................................

Patch Set 4: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I673a17f8c5dec66cc6c28c1ed44780a7a63927d7
Gerrit-Change-Number: 1094
Gerrit-PatchSet: 4
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Wed, 23 Jul 2025 13:38:51 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#8 lore raw

PATCH v4 1/1 dco: only pass struct context to init function

In reply to a message not in the archive

From: Antonio Quartulli <[email protected]...>

Future DCO code will require accessing the multi member of the context object.

For this reason a pointer to the context has to be stored in the DCO context along with the rest.

At this point, rather than making the call to ovpn_dco_init() longer with more and more parameters, pass the struct context only and let the implementation extract the needed fields.

Change-Id I673a17f8c5dec66cc6c28c1ed44780a7a63927d7

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1094
This mail reflects revision 4 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

src/openvpn/dco.h +3 -5
index f38316d..9078417 100644
@@ -104,12 +104,10 @@
 /**
  * Initialize the DCO context
  *
- * @param mode      the instance operating mode (P2P or multi-peer)
- * @param dco       the context to initialize
- * @param dev_node  device node, used on Windows to specify certain DCO adapter
+ * @param c         the main instance context
  * @return          true on success, false otherwise
  */
-bool ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node);
+bool ovpn_dco_init(struct context *c);
 
 /**
  * Open/create a DCO interface
@@ -297,7 +295,7 @@
 }
 
 static inline bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
     return true;
 }
src/openvpn/dco_freebsd.c +2 -2
index b8816c6..98d8fb5 100644
@@ -165,9 +165,9 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    if (open_fd(dco) < 0)
+    if (open_fd(&c->c1.tuntap->dco) < 0)
     {
         msg(M_ERR, "Failed to open socket");
         return false;
src/openvpn/dco_linux.c +8 -2
index 3652a49..ec6efaa 100644
@@ -438,9 +438,11 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case CM_TOP:
             dco->ifmode = OVPN_MODE_MP;
@@ -454,6 +456,10 @@
             ASSERT(false);
     }
 
+    /* store pointer to context as it may be required by message
+     * parsing routines
+     */
+    dco->c = c;
     ovpn_dco_init_netlink(dco);
     return true;
 }
src/openvpn/dco_linux.h +2 -0
index 676b8cd..5e61cf1 100644
@@ -65,6 +65,8 @@
     struct nl_cb *nl_cb;
     int status;
 
+    struct context *c;
+
     enum ovpn_mode ifmode;
 
     int ovpn_dco_id;
src/openvpn/dco_win.c +5 -3
index 83db739..e5a33a0 100644
@@ -188,9 +188,11 @@
  * state. The server socket should be initialized later by dco_mp_start_vpn().
  */
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case MODE_POINT_TO_POINT:
             dco->ifmode = DCO_MODE_P2P;
@@ -198,7 +200,7 @@
             break;
 
         case MODE_SERVER:
-            ovpn_dco_init_mp(dco, dev_node);
+            ovpn_dco_init_mp(dco, c->options.dev_node);
             break;
 
         default:
src/openvpn/init.c +1 -1
index 77747a2..aac8a6a 100644
@@ -2007,7 +2007,7 @@
 
         if (dco_enabled(&c->options))
         {
-            ovpn_dco_init(c->mode, &c->c1.tuntap->dco, c->options.dev_node);
+            ovpn_dco_init(c);
         }
 
         /* open the tun device */
#9 lore raw

[Openvpn-devel] [PATCH applied] Re: dco: only pass struct context to init function

Rarely I have seen a single ("simple!") patch cause *so* much build break e-mails... :-o - but anyway, v4 is good now, and passes compile on all platforms. It also passes actual client/server testing with DCO on Linux, and my critical stare-at-code test...

Your patch has been applied to the master branch.

commit a699681bb86c6e9a2c9f205543f60400208aea4b

Author: Antonio Quartulli
Date:   Wed Jul 23 15:39:11 2025 +0200
     dco: only pass struct context to init function

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg32293.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#10 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#5) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: dco: only pass struct context to init function
......................................................................

dco: only pass struct context to init function

Future DCO code will require accessing the multi member of the context object.

For this reason a pointer to the context has to be stored in the DCO context along with the rest.

At this point, rather than making the call to ovpn_dco_init() longer with more and more parameters, pass the struct context only and let the implementation extract the needed fields.

Change-Id I673a17f8c5dec66cc6c28c1ed44780a7a63927d7

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg32293.html

---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/dco_win.c
M src/openvpn/init.c

6 files changed, 21 insertions(+), 13 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/94/1094/5

src/openvpn/dco.h +3 -5
index f38316d..9078417 100644
@@ -104,12 +104,10 @@
 /**
  * Initialize the DCO context
  *
- * @param mode      the instance operating mode (P2P or multi-peer)
- * @param dco       the context to initialize
- * @param dev_node  device node, used on Windows to specify certain DCO adapter
+ * @param c         the main instance context
  * @return          true on success, false otherwise
  */
-bool ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node);
+bool ovpn_dco_init(struct context *c);
 
 /**
  * Open/create a DCO interface
@@ -297,7 +295,7 @@
 }
 
 static inline bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
     return true;
 }
src/openvpn/dco_freebsd.c +2 -2
index b8816c6..98d8fb5 100644
@@ -165,9 +165,9 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    if (open_fd(dco) < 0)
+    if (open_fd(&c->c1.tuntap->dco) < 0)
     {
         msg(M_ERR, "Failed to open socket");
         return false;
src/openvpn/dco_linux.c +8 -2
index 3652a49..ec6efaa 100644
@@ -438,9 +438,11 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case CM_TOP:
             dco->ifmode = OVPN_MODE_MP;
@@ -454,6 +456,10 @@
             ASSERT(false);
     }
 
+    /* store pointer to context as it may be required by message
+     * parsing routines
+     */
+    dco->c = c;
     ovpn_dco_init_netlink(dco);
     return true;
 }
src/openvpn/dco_linux.h +2 -0
index 676b8cd..5e61cf1 100644
@@ -65,6 +65,8 @@
     struct nl_cb *nl_cb;
     int status;
 
+    struct context *c;
+
     enum ovpn_mode ifmode;
 
     int ovpn_dco_id;
src/openvpn/dco_win.c +5 -3
index 83db739..e5a33a0 100644
@@ -188,9 +188,11 @@
  * state. The server socket should be initialized later by dco_mp_start_vpn().
  */
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case MODE_POINT_TO_POINT:
             dco->ifmode = DCO_MODE_P2P;
@@ -198,7 +200,7 @@
             break;
 
         case MODE_SERVER:
-            ovpn_dco_init_mp(dco, dev_node);
+            ovpn_dco_init_mp(dco, c->options.dev_node);
             break;
 
         default:
src/openvpn/init.c +1 -1
index 77747a2..aac8a6a 100644
@@ -2007,7 +2007,7 @@
 
         if (dco_enabled(&c->options))
         {
-            ovpn_dco_init(c->mode, &c->c1.tuntap->dco, c->options.dev_node);
+            ovpn_dco_init(c);
         }
 
         /* open the tun device */

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I673a17f8c5dec66cc6c28c1ed44780a7a63927d7
Gerrit-Change-Number: 1094
Gerrit-PatchSet: 5
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-MessageType: newpatchset

#11 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email )

Change subject: dco: only pass struct context to init function
......................................................................

dco: only pass struct context to init function

Future DCO code will require accessing the multi member of the context object.

For this reason a pointer to the context has to be stored in the DCO context along with the rest.

At this point, rather than making the call to ovpn_dco_init() longer with more and more parameters, pass the struct context only and let the implementation extract the needed fields.

Change-Id I673a17f8c5dec66cc6c28c1ed44780a7a63927d7

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg32293.html

---
M src/openvpn/dco.h
M src/openvpn/dco_freebsd.c
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/dco_win.c
M src/openvpn/init.c

6 files changed, 21 insertions(+), 13 deletions(-)
src/openvpn/dco.h +3 -5
index f38316d..9078417 100644
@@ -104,12 +104,10 @@
 /**
  * Initialize the DCO context
  *
- * @param mode      the instance operating mode (P2P or multi-peer)
- * @param dco       the context to initialize
- * @param dev_node  device node, used on Windows to specify certain DCO adapter
+ * @param c         the main instance context
  * @return          true on success, false otherwise
  */
-bool ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node);
+bool ovpn_dco_init(struct context *c);
 
 /**
  * Open/create a DCO interface
@@ -297,7 +295,7 @@
 }
 
 static inline bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
     return true;
 }
src/openvpn/dco_freebsd.c +2 -2
index b8816c6..98d8fb5 100644
@@ -165,9 +165,9 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    if (open_fd(dco) < 0)
+    if (open_fd(&c->c1.tuntap->dco) < 0)
     {
         msg(M_ERR, "Failed to open socket");
         return false;
src/openvpn/dco_linux.c +8 -2
index 3652a49..ec6efaa 100644
@@ -438,9 +438,11 @@
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case CM_TOP:
             dco->ifmode = OVPN_MODE_MP;
@@ -454,6 +456,10 @@
             ASSERT(false);
     }
 
+    /* store pointer to context as it may be required by message
+     * parsing routines
+     */
+    dco->c = c;
     ovpn_dco_init_netlink(dco);
     return true;
 }
src/openvpn/dco_linux.h +2 -0
index 676b8cd..5e61cf1 100644
@@ -65,6 +65,8 @@
     struct nl_cb *nl_cb;
     int status;
 
+    struct context *c;
+
     enum ovpn_mode ifmode;
 
     int ovpn_dco_id;
src/openvpn/dco_win.c +5 -3
index 83db739..e5a33a0 100644
@@ -188,9 +188,11 @@
  * state. The server socket should be initialized later by dco_mp_start_vpn().
  */
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case MODE_POINT_TO_POINT:
             dco->ifmode = DCO_MODE_P2P;
@@ -198,7 +200,7 @@
             break;
 
         case MODE_SERVER:
-            ovpn_dco_init_mp(dco, dev_node);
+            ovpn_dco_init_mp(dco, c->options.dev_node);
             break;
 
         default:
src/openvpn/init.c +1 -1
index 77747a2..aac8a6a 100644
@@ -2007,7 +2007,7 @@
 
         if (dco_enabled(&c->options))
         {
-            ovpn_dco_init(c->mode, &c->c1.tuntap->dco, c->options.dev_node);
+            ovpn_dco_init(c);
         }
 
         /* open the tun device */

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1094?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I673a17f8c5dec66cc6c28c1ed44780a7a63927d7
Gerrit-Change-Number: 1094
Gerrit-PatchSet: 5
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-MessageType: merged